package cn.wangsy.zhidao.p20170112;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Sorter {

	public static void main(String[] args) {

		List<Student> students = new ArrayList<Student>();
		
		Student student1 = new Student();
		student1.id = "1";
		student1.name = "张三";
		student1.score = 60;
		students.add(student1);
		
		Student student2 = new Student();
		student2.id = "2";
		student2.name = "李四";
		student2.score = 70;
		students.add(student2);
		
		Student student3 = new Student();
		student3.id = "3";
		student3.name = "王二";
		student3.score = 80;
		students.add(student3);
		
		Collections.sort(students);
		
		for(Student student:students){
			System.out.println("编号："+student.id+",姓名："+student.name+",成绩："+student.score);
		}
		
	}
	
}

class Student implements Comparable<Student>{
	
	public String id;
	public String name;
	public int score;
	
	@Override
	public int compareTo(Student o) {
		if(score>o.score){
			return -1;
		}else if(score<o.score){
			return 1;
		}
		return 0;
	}
	
}
